var app = getApp()
var util = require('../../../utils/util.js')

Page({
    data: {
        hideVerifyPhone: true,
        hideBindNewPhone: true,
        oldCode: '',
        oldCodeBtnDisabled: false,
        oldCodeStatus: '获取验证码',
        nextStepDisabled: false,
        newPhone: '',
        newPassword: '',
        newCode: '',
        newCodeBtnDisabled: false,
        newCodeStatus: '获取验证码',
        bindNewPhoneBtnDisabled: false,
        codeInterval: 60,
        oldPhonePicCodeUrl: '',
        newPhonePicCodeUrl: ''
    },
    oldPhonePicCode: '',
    newPhonePicCode: '',
    onLoad: function () {
      this.appInitial();

    },
    appInitial: function () {
      var this_ = this;
      wx.login({
        success: function (res) {
        
          wx.request({
            url: app.globalData.HOST,
            method: 'GET',
            data: {
              'appid': 'wx362df5afde518c83',
              'secret': '59b4e6f9fe02a2b382304d1fde950b1a',
              'js_code': res.code,
              'grant_type': 'authorization_code',
            },
            header: {
              'content-type': 'application/json'
            },
            success: function (res ) {
                  wx.setStorage({
                        key: "UserSession",
                        data: res.data
                      })
            },
            fail: function(ref){
              
            }
          });
        }
      });
    },
    GetUserAppid: function (user) {
      app.open_id(user);
      // app.globalData.user_appid = user;
    },
    logingo(e){  //点击 跳转
      app.turnToPage(e.currentTarget.dataset.router);
    },
    inputPhone: function (e) {  //账号
        this.data.newPhone = e.detail.value
    },
    inputPassword: function (e) {  //密码
        this.data.newPassword = e.detail.value
    },
  searchList:function(){
    this.getPhoneNumber();
  },
    getPhoneNumber: function (e) {  //登录

        var url = app.globalData.HOST + app.APILIST.login;
        var data = {
            "data":{
                "phone":this.data.newPhone,
                "password":this.data.newPassword,
            }
        };
        app.WxRequest(url,data,1,
            (res)=>{

                switch (res.status_code) {
                          case 200:
                       
                        app.UserInfo(res.data[0],res.data.token);
                        app.turnToPage('/pages/page10000/page10000');
                            break;
                          case 500:
                                  app.showToast({
                                      'title': res.Massage,
                                       'image' : '/images/cuo.png',
                                      'duration':1000
                                  });
                            break;
                        };
                        

        },(err)=>{
              console.log(res.data)
            // console.dir(err.response.data.Massage);
        });
    },
    inputOldPhonePicCode: function (e) {
        var value = e.detail.value;
        this.oldPhonePicCode = value;
    },
    inputNewPhonePicCode: function (e) {
        var value = e.detail.value;
        this.newPhonePicCode = value;
    },


})
